using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ColorDialogBoxProject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = richTextBox1.SelectionColor;

            if (colorDialog1.ShowDialog()==DialogResult.OK && richTextBox1.SelectionColor != colorDialog1.Color)
            {
                richTextBox1.SelectionColor= colorDialog1.Color;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ColorDialog myCD = new ColorDialog();
            myCD.Color = richTextBox1.SelectionColor;
            if (myCD.ShowDialog() == 
                DialogResult.OK &&
                richTextBox1.SelectionColor != myCD.Color)
            {
                richTextBox1.SelectionColor = myCD.Color;
            }
        }
    }
}